package com.ruoyi.project.sms.controller;

import com.ruoyi.common.utils.bootdo.PageUtils;
import com.ruoyi.common.utils.bootdo.Query;
import com.ruoyi.common.utils.bootdo.R;
import com.ruoyi.project.sms.domain.SmsCodeDO;
import com.ruoyi.project.sms.service.SmsCodeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 验证码
 * 
 * @author sys
 * @email 1992lcg@163.com
 * @date 2019-03-20 09:46:55
 */
 
@Controller
@RequestMapping("/sms/smsCode")
public class SmsCodeController {
	@Autowired
	private SmsCodeService smsCodeService;
	
	@GetMapping()
	@RequiresPermissions("sms:smsCode:smsCode")
	String SmsCode(){
	    return "sms/smsCode/smsCode";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("sms:smsCode:smsCode")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<SmsCodeDO> smsCodeList = smsCodeService.list(query);
		int total = smsCodeService.count(query);
		PageUtils pageUtils = new PageUtils(smsCodeList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("sms:smsCode:add")
	String add(){
	    return "sms/smsCode/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("sms:smsCode:edit")
	String edit(@PathVariable("id") Long id,Model model){
		SmsCodeDO smsCode = smsCodeService.get(id);
		model.addAttribute("smsCode", smsCode);
	    return "sms/smsCode/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("sms:smsCode:add")
	public R save(SmsCodeDO smsCode){
		if(smsCodeService.save(smsCode)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("sms:smsCode:edit")
	public R update( SmsCodeDO smsCode){
		smsCodeService.update(smsCode);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("sms:smsCode:remove")
	public R remove( Long id){
		if(smsCodeService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("sms:smsCode:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		smsCodeService.batchRemove(ids);
		return R.ok();
	}
	
}
